import {esri} from "../../api/esriAPI";

/**
 * arcgis标绘编辑工具
 * @class
 * */
export const SketchUtil = class  {
  _sketch = null;
  _manageView = null;
  _manageLayer = null;
  /**
   * 构造函数
   */
  constructor(manageView,manageLayer) {
      this._manageView = manageView;
      this._manageLayer = manageLayer;
  }
  add(position = "top-right"){
    let view = this._manageView.getMapView();
    if (!view) {
      return;
    }
    let layer = this._manageLayer.applyGraphicsLayer("arcgis标绘工具啦")
    const sketch = new esri.Sketch({
      layer: layer,
      view: view
    });
    this._sketch = sketch;
    view.ui.add(sketch,{position});
  }
  /**
   * 移除arcgis标绘编辑工具
   * @param {String} key 比例尺的key
   * @param {Object} view arcgis的view对象
   */
  remove(){
    let view = this._manageView.getMapView(this._mapId);
    if (!view) {
      return;
    }
    view.ui.remove(this._sketch);
  }
}


